package com.ruoyi.web.controller.official;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.personnel.service.IEmployeeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.official.domain.Money;
import com.ruoyi.official.service.IMoneyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 财务用款管理Controller
 * 
 * @author ruoyi
 * @date 2023-03-07
 */
@RestController
@RequestMapping("/official/money")
public class MoneyController extends BaseController
{
    @Autowired
    private IMoneyService moneyService;
    @Autowired
    private IEmployeeService iEmployeeService;

    /**
     * 查询财务用款管理列表
     */
    @PreAuthorize("@ss.hasPermi('official:money:list')")
    @GetMapping("/list")
    public TableDataInfo list(Money money)
    {
        System.out.println("+++++++++++++++++++++++++++++++++++++++++++");
        System.out.println(money.toString());
        startPage();
        List<Money> list = moneyService.selectMoneyList(money);
        return getDataTable(list);
    }

    /**
     * 导出财务用款管理列表
     */
    @PreAuthorize("@ss.hasPermi('official:money:export')")
    @Log(title = "财务用款管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Money money)
    {
        List<Money> list = moneyService.selectMoneyList(money);
        ExcelUtil<Money> util = new ExcelUtil<Money>(Money.class);
        util.exportExcel(response, list, "财务用款管理数据");
    }

    /**
     * 获取财务用款管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('official:money:query')")
    @GetMapping(value = "/{spendMoneyId}")
    public AjaxResult getInfo(@PathVariable("spendMoneyId") Integer spendMoneyId)
    {

        return success(moneyService.selectMoneyBySpendMoneyId(spendMoneyId));
    }

    /**
     * 新增财务用款管理
     */
    @PreAuthorize("@ss.hasPermi('official:money:add')")
    @Log(title = "财务用款管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Money money)
    {
        return toAjax(moneyService.insertMoney(money));
    }

    /**
     * 修改财务用款管理
     */
    @PreAuthorize("@ss.hasPermi('official:money:edit')")
    @Log(title = "财务用款管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Money money)
    {
        return toAjax(moneyService.updateMoney(money));
    }

    /**
     * 删除财务用款管理
     */
    @PreAuthorize("@ss.hasPermi('official:money:remove')")
    @Log(title = "财务用款管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{spendMoneyIds}")
    public AjaxResult remove(@PathVariable Integer[] spendMoneyIds)
    {
        return toAjax(moneyService.deleteMoneyBySpendMoneyIds(spendMoneyIds));
    }
}
